from flask import Flask, redirect, url_for

app = Flask(__name__)


@app.route('/index33/<user_id>')
def hello_world(user_id):
    return 'hello world  %s' % user_id


@app.route('/demo1')
def demo1():
    """重定向"""
    return redirect("http://www.baidu.com")


@app.route('/demo2')
def demo2():
    """重定向到根路径"""
    # 这里使用反向解析函数url_for：讲函数名称传入app.url_map，返回这个视图好那还苏对应的url
    return redirect(url_for('hello_world', user_id=222))


if __name__ == '__main__':
    print(app.url_map)
    """
    Map([<Rule '/demo1' (HEAD, GET, OPTIONS) -> demo1>,
 <Rule '/demo2' (HEAD, GET, OPTIONS) -> demo2>,
 <Rule '/index33/<user_id>' (HEAD, GET, OPTIONS) -> hello_world>,
 <Rule '/static/<filename>' (HEAD, GET, OPTIONS) -> static>])
    """
    app.run(debug=True)
